<?php
/* SVN FILE: $Id$ */
/**
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake.console.libs.templates.views
 * @since         CakePHP(tm) v 0.10.0.1076
 * @version       $Revision$
 * @modifiedby    $LastChangedBy$
 * @lastmodified  $Date$
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
?>
<!--[if !IE]>start section<![endif]-->
<div class="section table_section">
	<div class="section_inner">
		<div class="title_wrapper">
			<h2><?php echo $pluralHumanName;?></h2>
		</div>
		<div class="table_wrapper">
			<div class="table_wrapper_inner">
				<table cellpadding="0" cellspacing="0" width="100%">
					<tbody>
					<tr>
					<?php foreach ($scaffoldFields as $_field):?>
						<th><?php echo $paginator->sort($_field);?></th>
					<?php endforeach;?>
						<th><?php __('Actions');?></th>
					</tr>
					<?php
					$i = 0;
					foreach (${$pluralVar} as ${$singularVar}):
						$class = null;
						if ($i++ % 2 != 0) {
							$class = ' class="second"';
						}
					echo "\n";
						echo "\t<tr{$class}>\n";
							foreach ($scaffoldFields as $_field) {
								$isKey = false;
								if (!empty($associations['belongsTo'])) {
									foreach ($associations['belongsTo'] as $_alias => $_details) {
										if ($_field === $_details['foreignKey']) {
											$isKey = true;
											echo "\t\t<td>\n\t\t\t" . $html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t</td>\n";
											break;
										}
									}
								}
								if ($isKey !== true) {
									echo "\t\t<td>\n\t\t\t" . ${$singularVar}[$modelClass][$_field] . " \n\t\t</td>\n";
								}
							}
					
							echo "\t\t<td>\n";
							echo "\t\t\t" . $html->link(__('View', true), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])) . "\n";
						 	echo "\t\t\t" . $html->link(__('Edit', true), array('action' => 'edit',array('class'=>'edit'), ${$singularVar}[$modelClass][$primaryKey])) . "\n";
						 	echo "\t\t\t" . $html->link(__('Delete', true), array('action' => 'delete',array('class'=>'delete'), ${$singularVar}[$modelClass][$primaryKey]), null, __('Are you sure you want to delete', true).' ' . ${$singularVar}[$modelClass][$primaryKey]) . "\n";
							echo "\t\t</td>\n";
						echo "\t</tr>\n";
					
					endforeach;
					echo "\n";
					?>
					<tbody>
				</table>				
			</div>
		</div>
		<div class="pagination">
				<span class="page_no">
					<?php
					echo $paginator->counter(array(
					'format' => __('Page %page% of %pages%', true)
					));
					?>
				</span>
				<ul class="pag_list">
				<?php if($paginator->hasPrev()):?>				
				<li>
					<span class="left_button_pagination">&nbsp;</span>
						<?php echo $paginator->prev(__('Previous', true),array('class'=>'button small_button pag_nav'),null,null, array('class'=>'disabled'));?>
					<span class="right_button_pagination">&nbsp;</span>
				</li>
				<?php endif; ?>				
			  	<?php 
			 	echo $paginator->numbers(array(
						'tag' => 'li',
						'before'=> null,
			 		 	'after'=> null,
						 null,
						'modulus' => '8',
						'separator' => '',
						'first' => null, 
						'last' => null,
				));
				?>
				<?php if($paginator->hasNext()):?>				
				<li>

					<span class="left_button_pagination">&nbsp;</span>		
						<?php echo $paginator->next(__('Next', true),array('class'=>'button small_button pag_nav'),null, null, array('class'=>'disabled'));?>
					<span class="right_button_pagination">&nbsp;</span>
				</li>
				<?php endif; ?>		
				</ul>
			</div>
				<ul class="ul_buttons">
						<li><span class="button green_btn">
								<span>
									<span><?php echo $html->link('New '.$singularHumanName, array('action' => 'add')); ?></span>
								</span>
						</span></li>	
						<?php
						$done = array();
						foreach ($associations as $_type => $_data) {
							foreach ($_data as $_alias => $_details) {
								if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
									echo "\t\t<li><span class=\"button green_btn\"><span>
									<span>" . $html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</span></span></span></li>\n";
									echo "\t\t<li><span class=\"button green_btn\"><span>
									<span>" . $html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</span></span></span></li>\n";
									$done[] = $_details['controller'];
								}
							}
						}
					?>							
				</ul>	
			<div class="clear"></div>	
	</div>
</div>